#include<stdio.h>
#include<stdlib.h>
typedef struct ListNode {
	int val;
	struct ListNode* next;
}ListNode;
ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
    if (headA == NULL || headB == NULL)
        return NULL;
    ListNode* lA = headA;
    ListNode* lB = headB;
    while (lA != lB)
    {
        if (lA == NULL)
            lA = headB;
        else
            lA = lA->next;
        if (lB == NULL)
            lB = headA;
        else
            lB = lB->next;
    }
    return lA;
}
void test()
{
    ListNode* a1 = (ListNode*)malloc(sizeof(ListNode));
    ListNode* a2 = (ListNode*)malloc(sizeof(ListNode));
    ListNode* b1 = (ListNode*)malloc(sizeof(ListNode));
    ListNode* b2 = (ListNode*)malloc(sizeof(ListNode));
    ListNode* b3 = (ListNode*)malloc(sizeof(ListNode));
    ListNode* c1 = (ListNode*)malloc(sizeof(ListNode));
    ListNode* c2 = (ListNode*)malloc(sizeof(ListNode));
    ListNode* c3 = (ListNode*)malloc(sizeof(ListNode));
    a1->next = a2;
    b1->next = b2;
    b2->next = b3;
    a2->next = c1;
    b3->next = c1;
    c1->next = c2;
    c2->next = c3;
    c3->next = NULL;
    ListNode* ret = getIntersectionNode(a1, a2);
    printf("%p\n", ret);
}
int main()
{
    test();
	return 0;
}